package projeto.view;

import projeto.model.Usuario;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.ButtonModel;
import javax.swing.JOptionPane;
import projeto.controller.ControleBancoDeDados;

import projeto.controller.ControleDeUsuarios;
import projeto.model.*;

/**
 * Painel de Cadastro
 * @author Javatar
 */
@SuppressWarnings("serial")
public class PainelCadastro extends javax.swing.JPanel {
    
    private Usuario user;
    private ControleDeUsuarios userControl;
    private String nome;
    private String data = null;
    private String[] componentes;
    private String[][] matriz = new String[39][2];
    protected static boolean aberto;
    /** Creates new form PainelCadastro */
    public PainelCadastro() {
    	aberto = false;
    	userControl = FramePrincipal.userControl;
    	try{
    		userControl.criaUsuario();
    	}catch(Exception e){
    		
    	}
    	user = userControl.getUsuario();
    	componentes = new String[39];
        for(int i = 0;i < LeituraDeDados.tabelaRest.length - 2;i++){
            matriz[i][0] = componentes[i] = LeituraDeDados.tabelaRest[i+2];
            matriz[i][1] = "0 : N�o conhe�o";
        }
            
        initComponents();
        if(FramePrincipal.isOnline)
            jLabel1.setText("Esses dados serão salvos no nosso repositorio.");
        else
            jLabel1.setText("Esses dados serão salvos no arquivo local.");
        textBoxNomeUsuario.setText(userControl.getUsuario().getNome());
        botaoSelectOpiniao0.setSelected(true);
        
        
        
            
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
00
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        grupoOpnioes = new javax.swing.ButtonGroup();
        recomendacoes = new javax.swing.ButtonGroup();
        tituloCadastroUsuario = new javax.swing.JLabel();
        textNomeUsuario = new javax.swing.JLabel();
        textBoxNomeUsuario = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        tituloEstabelecimentos = new javax.swing.JLabel();
        comboBoxEstabelecimentos = new javax.swing.JComboBox();
        botaoSelectOpiniaoMenos5 = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        botaoSelectOpiniaoMenos4 = new javax.swing.JRadioButton();
        botaoSelectOpiniaoMenos2 = new javax.swing.JRadioButton();
        botaoSelectOpiniaoMenos1 = new javax.swing.JRadioButton();
        botaoSelectOpiniao1 = new javax.swing.JRadioButton();
        botaoSelectOpiniao2 = new javax.swing.JRadioButton();
        botaoSelectOpiniao3 = new javax.swing.JRadioButton();
        botaoSelectOpiniao4 = new javax.swing.JRadioButton();
        botaoSelectOpiniao5 = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaOpinioes = new javax.swing.JTable();
        botaoAlterarOpiniao = new javax.swing.JButton();
        botaoConfirmarDados = new javax.swing.JButton();
        botaoGerarRecomendacao = new javax.swing.JButton();
        botaoSalvarCadastro = new javax.swing.JButton();
        botaoSelectOpiniao0 = new javax.swing.JRadioButton();
        botaoSelectOpiniaoMenos3 = new javax.swing.JRadioButton();
        botaoSelectSemelhante = new javax.swing.JRadioButton();
        botaoSelectPopularidade = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();

        setPreferredSize(new java.awt.Dimension(780, 550));

        tituloCadastroUsuario.setFont(new java.awt.Font("Tahoma", 1, 18));
        tituloCadastroUsuario.setText("Cadastro de Usuário");

        textNomeUsuario.setFont(new java.awt.Font("Tahoma", 0, 14));
        textNomeUsuario.setText("Nome:");

        textBoxNomeUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textBoxNomeUsuarioActionPerformed(evt);
            }
        });

        tituloEstabelecimentos.setFont(new java.awt.Font("Tahoma", 0, 16));
        tituloEstabelecimentos.setText("Estabelecimentos");

        comboBoxEstabelecimentos.setModel(new javax.swing.DefaultComboBoxModel(componentes));
        comboBoxEstabelecimentos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBoxEstabelecimentosActionPerformed(evt);
            }
        });

        grupoOpnioes.add(botaoSelectOpiniaoMenos5);
        botaoSelectOpiniaoMenos5.setText("Detesto");
        botaoSelectOpiniaoMenos5.setActionCommand("-5 : Detesto");
        botaoSelectOpiniaoMenos5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSelectOpiniaoMenos5ActionPerformed(evt);
            }
        });

        jLabel4.setText("Opinião:");

        grupoOpnioes.add(botaoSelectOpiniaoMenos4);
        botaoSelectOpiniaoMenos4.setText("Muito ruim");
        botaoSelectOpiniaoMenos4.setActionCommand("-4 : Acho muito ruim");
        botaoSelectOpiniaoMenos4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSelectOpiniaoMenos4ActionPerformed(evt);
            }
        });

        grupoOpnioes.add(botaoSelectOpiniaoMenos2);
        botaoSelectOpiniaoMenos2.setText("Ruim");
        botaoSelectOpiniaoMenos2.setActionCommand("-2: Acho ruim");
        botaoSelectOpiniaoMenos2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSelectOpiniaoMenos2ActionPerformed(evt);
            }
        });

        grupoOpnioes.add(botaoSelectOpiniaoMenos1);
        botaoSelectOpiniaoMenos1.setText("Um pouco ruim");
        botaoSelectOpiniaoMenos1.setActionCommand("-1: Acho um pouco ruim");

        grupoOpnioes.add(botaoSelectOpiniao1);
        botaoSelectOpiniao1.setText("Não é ruim");
        botaoSelectOpiniao1.setActionCommand("1 : Não é ruim");

        grupoOpnioes.add(botaoSelectOpiniao2);
        botaoSelectOpiniao2.setText("É bonzinho");
        botaoSelectOpiniao2.setActionCommand("2 : É bonzinho");
        botaoSelectOpiniao2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSelectOpiniao2ActionPerformed(evt);
            }
        });

        grupoOpnioes.add(botaoSelectOpiniao3);
        botaoSelectOpiniao3.setText("Bastante bom");
        botaoSelectOpiniao3.setActionCommand("3: Bastante bom");

        grupoOpnioes.add(botaoSelectOpiniao4);
        botaoSelectOpiniao4.setText("Muito bom");
        botaoSelectOpiniao4.setActionCommand("4: Muito bom");

        grupoOpnioes.add(botaoSelectOpiniao5);
        botaoSelectOpiniao5.setText("Incrível, Sensacional(WooooW)");
        botaoSelectOpiniao5.setActionCommand("5: Incrível. sensacional. impressionante");

        tabelaOpinioes.setModel(new javax.swing.table.DefaultTableModel(
            matriz,
            new String [] {
                "Estabelecimento", "Opinião"
            }
        ){
            @Override
            public boolean isCellEditable(int row, int col){
                return false;
            }
        });
        jScrollPane1.setViewportView(tabelaOpinioes);

        botaoAlterarOpiniao.setText("Alterar");
        botaoAlterarOpiniao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarOpiniaoActionPerformed(evt);
            }
        });

        botaoConfirmarDados.setText("Confirmar");
        botaoConfirmarDados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoConfirmarDadosActionPerformed(evt);
            }
        });

        botaoGerarRecomendacao.setText("Gerar Recomendação");
        botaoGerarRecomendacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoGerarRecomendacaoActionPerformed(evt);
            }
        });

        botaoSalvarCadastro.setText("Salvar Cadastro");
        botaoSalvarCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarCadastroActionPerformed(evt);
            }
        });

        grupoOpnioes.add(botaoSelectOpiniao0);
        botaoSelectOpiniao0.setText("Não conheço");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, botaoSelectOpiniao0, org.jdesktop.beansbinding.ELProperty.create("${selected}"), botaoSelectOpiniao0, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        botaoSelectOpiniao0.setActionCommand("0 : Não conheço");

        grupoOpnioes.add(botaoSelectOpiniaoMenos3);
        botaoSelectOpiniaoMenos3.setText("Bastante ruim");
        botaoSelectOpiniaoMenos3.setActionCommand("-3 : Bastante ruim");

        recomendacoes.add(botaoSelectSemelhante);
        botaoSelectSemelhante.setSelected(true);
        botaoSelectSemelhante.setText("semelhanca");
        botaoSelectSemelhante.setActionCommand("semelhanca");

        recomendacoes.add(botaoSelectPopularidade);
        botaoSelectPopularidade.setText("Popularidade");
        botaoSelectPopularidade.setActionCommand("popularidade");
        botaoSelectPopularidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSelectPopularidadeActionPerformed(evt);
            }
        });

        jLabel1.setText("jLabel1");

        recomendacoes.add(jRadioButton1);
        jRadioButton1.setText("Recomendação por Cosseno");
        jRadioButton1.setActionCommand("cosseno");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(279, 279, 279)
                        .addComponent(tituloCadastroUsuario))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(183, 183, 183)
                                .addComponent(textNomeUsuario)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textBoxNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 760, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(329, 329, 329)
                        .addComponent(tituloEstabelecimentos)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(73, 73, 73))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botaoSelectSemelhante)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botaoSelectPopularidade)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jRadioButton1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botaoConfirmarDados)
                                .addGap(58, 58, 58)
                                .addComponent(botaoGerarRecomendacao)
                                .addGap(31, 31, 31)
                                .addComponent(botaoSalvarCadastro)))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(botaoAlterarOpiniao))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(botaoSelectOpiniao0)
                                    .addComponent(botaoSelectOpiniaoMenos5)
                                    .addComponent(botaoSelectOpiniaoMenos4)
                                    .addComponent(botaoSelectOpiniaoMenos3)
                                    .addComponent(botaoSelectOpiniaoMenos2)
                                    .addComponent(botaoSelectOpiniaoMenos1)
                                    .addComponent(botaoSelectOpiniao1)
                                    .addComponent(botaoSelectOpiniao2)
                                    .addComponent(botaoSelectOpiniao3)
                                    .addComponent(botaoSelectOpiniao4)
                                    .addComponent(botaoSelectOpiniao5))
                                .addContainerGap(186, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(comboBoxEstabelecimentos, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel1)))
                        .addContainerGap(162, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tituloCadastroUsuario)
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textNomeUsuario)
                    .addComponent(textBoxNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tituloEstabelecimentos)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botaoSelectSemelhante)
                            .addComponent(botaoSelectPopularidade)
                            .addComponent(jRadioButton1))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botaoGerarRecomendacao)
                            .addComponent(botaoSalvarCadastro)
                            .addComponent(botaoConfirmarDados)
                            .addComponent(jLabel1)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(comboBoxEstabelecimentos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botaoSelectOpiniao0)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniaoMenos5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniaoMenos4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniaoMenos3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniaoMenos2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniaoMenos1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniao1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniao2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniao3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniao4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSelectOpiniao5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoAlterarOpiniao)))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoSelectOpiniaoMenos5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSelectOpiniaoMenos5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSelectOpiniaoMenos5ActionPerformed

    private void botaoSelectOpiniaoMenos4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSelectOpiniaoMenos4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSelectOpiniaoMenos4ActionPerformed

    private void botaoAlterarOpiniaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarOpiniaoActionPerformed
        ButtonModel indice = grupoOpnioes.getSelection();
        tabelaOpinioes.setValueAt(indice.getActionCommand(), comboBoxEstabelecimentos.getSelectedIndex(),1 );
        userControl.getUsuario().getOpnioes().set(comboBoxEstabelecimentos.getSelectedIndex(), Integer.parseInt(indice.getActionCommand().split(":")[0].trim()));

    }//GEN-LAST:event_botaoAlterarOpiniaoActionPerformed

    private void botaoSelectOpiniaoMenos2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSelectOpiniaoMenos2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSelectOpiniaoMenos2ActionPerformed

    private void botaoSelectOpiniao2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSelectOpiniao2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSelectOpiniao2ActionPerformed

    private void botaoGerarRecomendacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoGerarRecomendacaoActionPerformed
           ButtonModel botao = recomendacoes.getSelection();
        if(data != null){	
            user = userControl.getUsuario();
             int qntd_rec;
       if(botao.getActionCommand().equals("popularidade")){
           if(!PainelRecomendacoes.aberto){
        	   Recomenda Popularidade = RecomendaPopularidade.getInstance();
               qntd_rec = Integer.parseInt(JOptionPane.showInputDialog("Quantidade de recomenda��es"));
               FramePrincipal.userControl.addUsuario(user);
               List<Estabelecimento> estabelecimentos = Popularidade.getRecomendacao(FramePrincipal.estabelecimentos, FramePrincipal.userControl.getListaDeUsuarios(),null, qntd_rec);
               FramePrincipal.userControl.removeUsuario(user);
               FramePrincipal.adicionaPainelJTabbedPane1("Recomenda��es", new PainelRecomendacoes(LeituraDeDados.geraMatrizDadosEsts(estabelecimentos),FramePrincipal.userControl.getUsuario()));
               PainelRecomendacoes.aberto = true;
           }
           
       }else if(botao.getActionCommand().equals("semelhanca")){
           try{
               if(!PainelRecomendacoes.aberto){
            	   Recomenda Escalar = RecomendaEscalar.getInstance();
                   qntd_rec = Integer.parseInt(JOptionPane.showInputDialog("Quantidade de recomenda��es"));
                   List<Estabelecimento> estabelecimentos =  Escalar.getRecomendacao(FramePrincipal.estabelecimentos, FramePrincipal.userControl.getListaDeUsuarios(), user , qntd_rec);
                   FramePrincipal.adicionaPainelJTabbedPane1("Recomenda��es", new PainelRecomendacoes(LeituraDeDados.geraMatrizDadosEsts(estabelecimentos),FramePrincipal.userControl.getUsuario()));
                   PainelRecomendacoes.aberto = true;
               }
           }catch(Exception e){
                JOptionPane.showMessageDialog(null,"valor invalido!!","Erro", JOptionPane.ERROR_MESSAGE);
           }
       }else{
           try{
               if(!PainelRecomendacoes.aberto){
            	   Recomenda Cosseno = RecomendaCosseno.getInstance();
                   qntd_rec = Integer.parseInt(JOptionPane.showInputDialog("Quantidade de recomenda��es"));
                   List<Estabelecimento> estabelecimentos =  Cosseno.getRecomendacao(FramePrincipal.estabelecimentos, FramePrincipal.userControl.getListaDeUsuarios(), user , qntd_rec);
                   FramePrincipal.adicionaPainelJTabbedPane1("Recomenda��es", new PainelRecomendacoes(LeituraDeDados.geraMatrizDadosEsts(estabelecimentos),FramePrincipal.userControl.getUsuario()));
                   PainelRecomendacoes.aberto = true;
               }
           }catch(Exception e){
                JOptionPane.showMessageDialog(null,"valor invalido!!","Erro", JOptionPane.ERROR_MESSAGE);
           }
       }
        
        }else     
            JOptionPane.showMessageDialog(null,"Confirme os dados primeiro","Erro", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_botaoGerarRecomendacaoActionPerformed

    private void botaoConfirmarDadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoConfirmarDadosActionPerformed
        Date date = new Date();
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        nome = textBoxNomeUsuario.getText();
        data = formato.format(date);
        try{
            userControl.getUsuario().setNome(nome);
        }catch(Exception e){
            
        }
        try{
            userControl.getUsuario().setData(data);
        }catch(Exception e){
            
        }
        
    }//GEN-LAST:event_botaoConfirmarDadosActionPerformed

    private void botaoSalvarCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarCadastroActionPerformed
        if(!FramePrincipal.isOnline){
            if(textBoxNomeUsuario.getText().trim().equals("") || textBoxNomeUsuario.getText().trim().toLowerCase().indexOf("anonimo") != -1){
                JOptionPane.showMessageDialog(null,"Nome não pode ser vazio nem conter 'anonimo'.","Erro", JOptionPane.ERROR_MESSAGE);
            }else{
            if(userControl.getUsuario().getNome().equals(textBoxNomeUsuario.getText()) && data != null){
                if(userControl.escreveUsuario(user, PainelArquivo.getArquivo().getAbsolutePath())){
                    JOptionPane.showMessageDialog(null,"Cadastrado realizado com sucesso","OK", JOptionPane.PLAIN_MESSAGE);
                    PainelCadastro.aberto = false;
                    FramePrincipal.jTabbedPane1.remove(this);

                }else 
                    JOptionPane.showMessageDialog(null,"Problema ao realizar cadastro","Erro", JOptionPane.ERROR_MESSAGE);
            }else
                JOptionPane.showMessageDialog(null,"Confirme os dados primeiro","Erro", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            if(ControleBancoDeDados.verificaConexao()){
                if(textBoxNomeUsuario.getText().trim().equals("") || textBoxNomeUsuario.getText().trim().toLowerCase().indexOf("anonimo") != -1){
                JOptionPane.showMessageDialog(null,"Nome não pode ser vazio nem conter 'anonimo'.","Erro", JOptionPane.ERROR_MESSAGE);
            }else{
            if(userControl.getUsuario().getNome().equals(textBoxNomeUsuario.getText()) && data != null){
                if(ControleBancoDeDados.adicionaOpiniao(user)){
                    JOptionPane.showMessageDialog(null,"Cadastrado realizado com sucesso","OK", JOptionPane.PLAIN_MESSAGE);
                    PainelCadastro.aberto = false;
                    FramePrincipal.jTabbedPane1.remove(this);

                }else 
                    JOptionPane.showMessageDialog(null,"Problema ao realizar cadastro","Erro", JOptionPane.ERROR_MESSAGE);
            }else
                JOptionPane.showMessageDialog(null,"Confirme os dados primeiro","Erro", JOptionPane.ERROR_MESSAGE);
            }
            }
        }
    }//GEN-LAST:event_botaoSalvarCadastroActionPerformed

    private void comboBoxEstabelecimentosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBoxEstabelecimentosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboBoxEstabelecimentosActionPerformed

    private void textBoxNomeUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textBoxNomeUsuarioActionPerformed
        
    }//GEN-LAST:event_textBoxNomeUsuarioActionPerformed

    private void botaoSelectPopularidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSelectPopularidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSelectPopularidadeActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlterarOpiniao;
    private javax.swing.JButton botaoConfirmarDados;
    private javax.swing.JButton botaoGerarRecomendacao;
    private javax.swing.JButton botaoSalvarCadastro;
    private javax.swing.JRadioButton botaoSelectOpiniao0;
    private javax.swing.JRadioButton botaoSelectOpiniao1;
    private javax.swing.JRadioButton botaoSelectOpiniao2;
    private javax.swing.JRadioButton botaoSelectOpiniao3;
    private javax.swing.JRadioButton botaoSelectOpiniao4;
    private javax.swing.JRadioButton botaoSelectOpiniao5;
    private javax.swing.JRadioButton botaoSelectOpiniaoMenos1;
    private javax.swing.JRadioButton botaoSelectOpiniaoMenos2;
    private javax.swing.JRadioButton botaoSelectOpiniaoMenos3;
    private javax.swing.JRadioButton botaoSelectOpiniaoMenos4;
    private javax.swing.JRadioButton botaoSelectOpiniaoMenos5;
    private javax.swing.JRadioButton botaoSelectPopularidade;
    private javax.swing.JRadioButton botaoSelectSemelhante;
    private javax.swing.JComboBox comboBoxEstabelecimentos;
    private javax.swing.ButtonGroup grupoOpnioes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.ButtonGroup recomendacoes;
    private javax.swing.JTable tabelaOpinioes;
    private javax.swing.JTextField textBoxNomeUsuario;
    private javax.swing.JLabel textNomeUsuario;
    private javax.swing.JLabel tituloCadastroUsuario;
    private javax.swing.JLabel tituloEstabelecimentos;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
